home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / inifil / inifile.bas < prev    next >
Encoding:
BASIC Source File  |  1994-09-23  |  2.2 KB  |  79 lines

  1. Option Explicit
  2.  
  3. Dim msDir As String
  4. Dim mnDirNameLength As Integer
  5.  
  6. Declare Function KRN_GetWindowsDirectory Lib "Kernel" Alias "GetWindowsDirectory" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  7. Declare Function KRN_GetSystemDirectory Lib "Kernel" Alias "GetSystemDirectory" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  8.  
  9. Function CopyFile (rsFileName As String, rsDestination As String) As Integer
  10. '
  11. '   This routine will copy a file to a given destination.
  12. '
  13.     CopyFile = False
  14.  
  15.     On Error GoTo CopyFile_ER
  16.  
  17.     FileCopy rsFileName, rsDestination
  18.     Exit Function
  19.  
  20. CopyFile_ER:
  21.     CopyFile = Err
  22.     gsMsg = "Error in CopyFile, Error is " & Error
  23.     gsMsgTitle = "Copy File"
  24.     Exit Function
  25. End Function
  26.  
  27. Function FileExists (rsFilePath As String) As Integer
  28. '
  29. '   This routine will check for the existence of a
  30. '   file by attempting an OPEN. It will return a TRUE
  31. '   value if the file exists, FALSE otherwise.
  32. '
  33.     Dim nFile As Integer
  34.  
  35.     nFile = FreeFile
  36.  
  37.     On Error Resume Next
  38.     Open rsFilePath For Input As nFile
  39.     If Err = 0 Then
  40.         FileExists = True
  41.     Else
  42.         FileExists = False
  43.     End If
  44.     Close nFile
  45. End Function
  46.  
  47. Function GetWinDir () As String
  48. '
  49. '   This routine will find and return the users windows
  50. '   directory.
  51. '
  52.     msDir = String$(145, 0)              ' Size Buffer
  53.     mnDirNameLength = KRN_GetWindowsDirectory(msDir, 145)  ' Make API Call
  54.     msDir = Left$(msDir, mnDirNameLength)              ' Trim Buffer
  55.  
  56.     If Right$(msDir, 1) <> "\" Then      ' Add \ if necessary
  57.         GetWinDir = msDir + "\"
  58.     Else
  59.         GetWinDir = msDir
  60.     End If
  61. End Function
  62.  
  63. Function GetWinSysDir () As String
  64. '
  65. '   This routine will return the users windows system
  66. '   directory
  67. '
  68.     msDir = String$(145, 0)                 ' Size Buffer
  69.     mnDirNameLength = KRN_GetSystemDirectory(msDir, 145)      ' Make API Call
  70.     msDir = Left$(msDir, mnDirNameLength)                 ' Trim Buffer
  71.  
  72.     If Right$(msDir, 1) <> "\" Then         ' Add \ if necessary
  73.         GetWinSysDir = msDir + "\"
  74.     Else
  75.         GetWinSysDir = msDir
  76.     End If
  77. End Function
  78.  
  79.